import { LANGUAGE, TAGS_VIEW } from '@/constants'
import { getItem, setItem } from '@/utils/storage'

export default {
  namespaced: true,
  state: () => ({
    openLeftMenu: true,
    language: getItem(LANGUAGE) || 'zh',
    tagsViewList: getItem(TAGS_VIEW) || []
  }),
  mutations: {
    changeOpenLeftMenu(state) {
      state.openLeftMenu = !state.openLeftMenu
    },
    setLanguage(state, language) {
      state.language = language
      setItem(LANGUAGE, language)
    },
    addTagsView(state, route) {
      const isExist = state.tagsViewList.some(
        (item) => item.path === route.path
      )
      if (!isExist) {
        state.tagsViewList.push(route)
        setItem(TAGS_VIEW, state.tagsViewList)
      }
    }
  },
  actions: {}
}
